package pl.nazaweb.imedproplus.model.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import pl.nazaweb.imedproplus.model.interfaces.IAppointment;

@Entity
@Table(name = "appointment")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Appointment.findAll", query = "SELECT a FROM Appointment a"),
    @NamedQuery(name = "Appointment.findById", query = "SELECT a FROM Appointment a WHERE a.id = :id"),
    @NamedQuery(name = "Appointment.findByDay", query = "SELECT a FROM Appointment a WHERE a.day = :day"),
    @NamedQuery(name = "Appointment.findByDateFrom", query = "SELECT a FROM Appointment a WHERE a.dateFrom = :dateFrom"),
    @NamedQuery(name = "Appointment.findByDateTo", query = "SELECT a FROM Appointment a WHERE a.dateTo = :dateTo"),
    @NamedQuery(name = "Appointment.findByPlannedNumberNormalVisit", query = "SELECT a FROM Appointment a WHERE a.plannedNumberNormalVisit = :plannedNumberNormalVisit"),
    @NamedQuery(name = "Appointment.findByPlannedNumberFirstVisit", query = "SELECT a FROM Appointment a WHERE a.plannedNumberFirstVisit = :plannedNumberFirstVisit")})
public class Appointment implements Serializable, IAppointment {
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_from")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateFrom;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_to")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateTo;
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name="appointment_sequence_", sequenceName="appointment_sequence", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="appointment_sequence_")
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "day")
    private String day;
    @Column(name = "planned_number_normal_visit")
    private Integer plannedNumberNormalVisit;
    @Column(name = "planned_number_first_visit")
    private Integer plannedNumberFirstVisit;
    @JoinColumn(name = "organization_unit", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private OrganizationStructure organizationUnit;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "appointment")
    private List<Reservation> reservationList;

    public Appointment() {
    }

    public Appointment(Long id) {
        this.id = id;
    }

    public Appointment(Long id, String day, Date dateFrom, Date dateTo) {
        this.id = id;
        this.day = day;
        this.dateFrom = dateFrom;
        this.dateTo = dateTo;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String getDay() {
        return day;
    }

    @Override
    public void setDay(String day) {
        this.day = day;
    }

    @Override
    public Date getDateFrom() {
        return dateFrom;
    }

    @Override
    public void setDateFrom(Date dateFrom) {
        this.dateFrom = dateFrom;
    }

    @Override
    public Date getDateTo() {
        return dateTo;
    }

    @Override
    public void setDateTo(Date dateTo) {
        this.dateTo = dateTo;
    }

    @Override
    public Integer getPlannedNumberNormalVisit() {
        return plannedNumberNormalVisit;
    }

    @Override
    public void setPlannedNumberNormalVisit(Integer plannedNumberNormalVisit) {
        this.plannedNumberNormalVisit = plannedNumberNormalVisit;
    }

    @Override
    public Integer getPlannedNumberFirstVisit() {
        return plannedNumberFirstVisit;
    }

    @Override
    public void setPlannedNumberFirstVisit(Integer plannedNumberFirstVisit) {
        this.plannedNumberFirstVisit = plannedNumberFirstVisit;
    }

    @Override
    public OrganizationStructure getOrganizationUnit() {
        return organizationUnit;
    }

    @Override
    public void setOrganizationUnit(OrganizationStructure organizationUnit) {
        this.organizationUnit = organizationUnit;
    }

    @XmlTransient
    @Override
    public List<Reservation> getReservationList() {
        return reservationList;
    }

    @Override
    public void setReservationList(List<Reservation> reservationList) {
        this.reservationList = reservationList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Appointment)) {
            return false;
        }
        Appointment other = (Appointment) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.nazaweb.imedproplus.model.entity.Appointment[ id=" + id + " ]";
    }

}
